<link rel="stylesheet" href="<?php echo $this->basePath('js/hiprint/css/hiprint.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('js/hiprint/css/print-lock.css'); ?>">
<link href="<?php echo $this->basePath('js/hiprint/css/print-lock.css'); ?>" media="print" rel="stylesheet">
<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>
        <h1 class="pull-right" id="dberp-menu-top">
            <a href="<?php echo $this->url('print-template');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回打印模板列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm" onclick="$('#templateBody').val(JSON.stringify(hiprintTemplate.getJsonTid()));"><i class="fa fa-check"></i> <?php echo $this->translate('保存设置'); ?></button>
            <?php echo $this->HelpUrl('printTemplate'); ?>
        </h1>
    </section>
    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->templateInfo->getTemplateTitle(); ?></h3> <?php if (empty(\Admin\Data\Common::configValue('base', 'config')['company_logo'])) { ?><span class="text-red text-bold"><?php echo $this->translate('公司Logo需要在系统设置中进行设置'); ?></span><?php } ?>

                    </div>

                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('状态'); ?></label>
                            <div class="col-sm-6">
                                <div class="checkbox">
                                    <label>
                                        <?php echo $this->formElement($form->get('templateState')); ?> <?php echo $this->translate('启用'); ?>
                                        <?php echo $this->formElementErrors($form->get('templateState'), ['class'=>'error-message']); ?>
                                    </label>
                                </div>
                                <?php echo $this->formElement($form->get('templateBody')); ?>
                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="small-printElement-types hiprintEpContainer">

                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="hiprint-toolbar" style="margin-top:15px;margin-bottom: 20px;">
                                <ul>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('A3')">A3</a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('A4')">A4</a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('A5')">A5</a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('B3')">B3</a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('B4')">B4</a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="setPaper('B5')">B5</a></li>
                                    <li><a class="hiprint-toolbar-item">自定义</a></li>
                                    <li><a class="hiprint-toolbar-item"><input type="text" id="customWidth" style="width: 50px;height: 19px;border: 0px;" placeholder="<?php echo $this->translate('宽'); ?>/mm" /></a></li>
                                    <li><a class="hiprint-toolbar-item"><input type="text" id="customHeight" style="width: 50px;height: 19px;border: 0px;" placeholder="<?php echo $this->translate('高'); ?>/mm" /></a></li>

                                    <li><a class="hiprint-toolbar-item" onclick="setPaper($('#customWidth').val(),$('#customHeight').val())"><?php echo $this->translate('确定'); ?></a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="rotatePaper()"><?php echo $this->translate('旋转'); ?></a></li>
                                    <li><a class="hiprint-toolbar-item" onclick="clearTemplate()"><?php echo $this->translate('清空'); ?></a></li>
                                    <li>
                                        <a class="btn hiprint-toolbar-item " style="color: #fff;
    background-color: #d9534f;
    border-color: #d43f3a;" onclick="preview()"><?php echo $this->translate('预览'); ?></a>
                                    </li>
                                    <li>
                                        <a class="btn hiprint-toolbar-item " style="color: #fff;
    background-color: #d9534f;
    border-color: #d43f3a;" onclick="directPrint()"><?php echo $this->translate('打印'); ?></a>
                                    </li>
                                </ul>
                            </div>

                            <div id="templateDesignDiv"></div>
                        </div>
                        <div class="col-md-2" id="PrintElementOptionSetting"></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"><?php echo $this->translate('打印预览'); ?></h4>
                    </div>
                    <div class="modal-body">
                        <button type="button" class="btn btn-danger" onclick="printByHtml()"><?php echo $this->translate('打印'); ?></button>
                        <div class="prevViewDiv"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('关闭'); ?></button>

                    </div>
                </div>
            </div>
        </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>

    <script src="<?php echo $this->basePath('js/hiprint/polyfill.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/hiprint.bundle.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jquery.hiwprint.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/JsBarcode.all.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/qrcode.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jquery.minicolors.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jspdf/canvas2image.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jspdf/canvg.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jspdf/html2canvas.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/plugins/jspdf/jspdf.min.js'); ?>"></script>
    <script src="<?php echo $this->basePath('js/hiprint/hiprint.config.js'); ?>"></script>

    <script>
        var hiprintTemplate;
        $(document).ready(function() {
            hiprint.init({
                providers: [new configElementTypeProvider()]
            });

            //设置左侧拖拽事件
            hiprint.PrintElementTypeManager.build('.hiprintEpContainer', 'leftModule');

            hiprintTemplate = new hiprint.PrintTemplate({
                template: configPrintJson,
                settingContainer: '#PrintElementOptionSetting'
            });

            hiprintTemplate.design('#templateDesignDiv');
        });

        //清空
        var clearTemplate = function () {
            hiprintTemplate.clear();
        }
        //旋转
        var rotatePaper = function () {
            hiprintTemplate.rotatePaper();
        }
        //预览
        var preview = function () {
            $('#myModal .modal-body').html(hiprintTemplate.getHtml(printData))
            $('#myModal').modal('show')
        }

        //直接调用浏览器的打印
        directPrint = function () {
            hiprintTemplate.print(printData);

        }

        //设置打印尺寸
        var setPaper = function (paperTypeOrWidth, height) {
            hiprintTemplate.setPaper(paperTypeOrWidth, height);
        }

        <?php echo $this->partial('admin/print-template/configElementTypeProvider.phtml', ['templateCode' => $this->templateInfo->getTemplateCode()]); ?>

        var configPrintJson = <?php echo $this->templateInfo->getTemplateBody() ?>;

        var printData = {};
    </script>
</div>
